package com.fuhao.controller;

import com.fuhao.model.Mail;
import com.fuhao.model.User;
import com.fuhao.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhang
 * @title: SendController
 * @projectName springactivemq
 * @description: TODO
 * @date 2019/5/1417:48
 */
@RestController
public class SendController {

    @Autowired
    @Qualifier("queue")
    private ProductService queueProductService;

    @Autowired
    @Qualifier("topic")
    private ProductService topicProductService;

    @RequestMapping("/sendQueue")
    public String sendQueue(){
//        long startTime=System.currentTimeMillis();
//        for (int i = 0;i < 2000;i++){
            System.out.println("发送消息");
            queueProductService.sendMail(new Mail(1,"queue生产者发送消息到myqueue"));
//            System.out.println("执行业务");
//        }
//        long endTime=System.currentTimeMillis(); //获取结束时间
//        System.out.println("总的执行时间为："+(endTime-startTime));
        return "success";
    }

    @RequestMapping("/sendTopic")
    public String sendTopic(){
        for (int i = 0;i < 1000;i++){
            topicProductService.sendMail(new Mail(2,"topic生产者发送消息到mytopic"));
        }
        return "success";
    }

    @RequestMapping("/sendQueueDB")
    public String sendQueueDB(){

        System.out.println("发送消息");
        User user = new User();
        user.setUsername("AAA");
        user.setAge(19);
        user.setSex(0);
        queueProductService.sendUser(user);
        return "success";
    }


}
